package com.qf.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qf.pojo.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/search")
public class SearchController {
    @RequestMapping("/test")
    public String test1(){
        return "这是Search服务被调用了";
    }


    //远程调用带传参
    @RequestMapping("/query/{id}")
    @HystrixCommand(fallbackMethod = "findUserByIdHystrix")
    public User findUserById(@PathVariable("id") Integer id){
        System.out.println("--------id----"+id);
        //模拟被调用方出错
        int i=1/0;
        User user = new User();


        user.setId(1);
        user.setName("成龙");
        user.setAge(24);
        user.setBirthday(new Date());
        return user;
    }
//    @RequestMapping("/query/{id}")
    public User findUserByIdHystrix( Integer id){
        User user = new User();
        user.setId(1);
        user.setName("这里有异常------就是被调用方的异常");
        user.setAge(89);
        user.setBirthday(new Date());
        return user;
    }
}
